import utils from '../../utils';

const LOAD_DATA = 'system/LOAD_DATA';
const LOAD_DETAIL = 'system/LOAD_DETAIL';
const LOAD_ADDRESS = 'system/LOAD_ADDRESS';

const initialState = {
    labdata: {},
    detail: {},
    address: {},
    labload: false,
    detailload: false,
    addressload: false
};

export default function reducer(state = initialState, action = {}) {
    switch (action.type) {
        case LOAD_DATA:
            return {
                ...state,
                labdata: action.data,
                labload: true
            };
        case LOAD_DETAIL:
            return {
                ...state,
                detail: action.data,
                detailload: true
            };
        case LOAD_ADDRESS:
            return {
                ...state,
                address: action.data,
                addressload: true
            };
        default:
            return state;
    }
}

export const loadData = utils.createAction(
    LOAD_DATA,
    ({query, ctxCookie = ''} = {}) => utils.get('/api/labname', null, ctxCookie)
);

export const loadDetail = utils.createAction(
    LOAD_DETAIL,
    ({query, ctxCookie = ''} = {}) => utils.get('/api/labdetail', null, ctxCookie)
);

export const loadAddress = utils.createAction(
    LOAD_ADDRESS,
    ({query, ctxCookie = ''} = {}) => utils.get('/api/myaddress', null, ctxCookie)
);
